﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EasyUI.Master" AutoEventWireup="true" CodeBehind="ListR.aspx.cs" Inherits="jnxc.Web.toolsRecord.ListR" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    var level = data[0].level;                    
                    if (level == 1) {                        
                        $("#btnedit").show();
                       
                    }
                    else {
                        $("#btnedit").hide();

                    }
                }
            });
            $('#mhid').combotree({
                url: '../harmfulinfo/GetHarm.ashx',
                method: 'post',
                queryParams: { "action": "querypro" },
                required: true
            });
            $('#mpid').combotree({
                url: '../plantinfo/GetPlant.ashx',
                method: 'post',
                queryParams: { "action": "querypro" },
                required: true
            });
            InitGird();
        });
        function getArgs() {
            var args = {};
            var match = null;
            var search = decodeURIComponent(location.search.substring(1));            
            return search;
        }
        function outword() {
            DownLoad(getArgs());
        }
        function DownLoad(args) {
            var form = $("<form>");   //定义一个form表单
            form.attr('style', 'display:none');   //在form表单中添加查询参数
            form.attr('target', '');
            form.attr('method', 'post');
            form.attr('action', "GetTools.ashx?action=tt&" + args);

            $('body').append(form);  //将表单放置在web中 
            //form.append(input1);   //将查询参数控件提交到表单上
            form.submit();

        }

        //初始化表格
        function InitGird() {
            var args = getArgs();
            $('#tt').datagrid({
                title: '诱虫灯（引诱剂、粘虫色板）调查记录表', //表格标题
                url: 'GetTools.ashx?' + args, //请求数据的页面
                sortName: 'toolsId', //排序字段
                idField: 'toolsId', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                singleSelect: true,
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,                
                method: 'post',
                frozenColumns: [[
                    { field: 'ckb', checkbox: true },
                    {
                        title: '县', field: 'coname', width: 100, formatter: function (value, row) {
                            return row.coname + '(' + row.cobh + ')';
                        }
                    },
                    {
                        title: '乡镇', field: 'tname', width:100, formatter: function (value, row) {
                            return row.tname + '(' + row.tbh + ')';
                        }
                    },

                    { title: '诱虫类所在<br/>小班（林班）', align:'center',width: 100, field: 'xbhbh' },
                    { title: '林分组成', width: 80, field: 'lfzc' },
                    { title: '林分面积', width: 80, field: 'xbzone' },
                    { title: '主要树种', width:80, field: 'plantname' },
                    { title: '经度', width: 80, field: 'jd' },
                    { title: '纬度', width: 80, field: 'wd' },
                    { title: '海拨', width: 80, field: 'hb' },
                    { title: '上传时间', width: 120, field: 'investigationTime' }
                ]],

                columns: [
                    [                   
                    { title: '昆虫', field: 'hname', rowspan: 2 },
                    {
                        title: '诱虫数量（头）', colspan: 3

                    },
                    { title: '备注', field: 'remark', rowspan: 2 }],
                    [
                    {
                        title: '合计',field: 'hname1' ,  formatter: function (value, row, index) {
                           return parseInt(row.femaleCount) + parseInt(row.maleCount);
                        }
                    },
                    { title: '诱虫数量（雌）', field: 'femaleCount' },
                    { title: '诱虫数量（雄）', field: 'maleCount' }
                    ]
                ],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号

            });


        }
        function editUser() {
            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改数据');
                $('#uid').val(row.toolsId);
                
                $('#fm').form('load', row);
                
            }
        }
        //添加        
        function saveUser() {            
            var f = $('#fm');
           
                f.form('submit', {
                    url: "GetTools.ashx?action=modify",
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "修改失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });            
        }
        function removeUser() {

            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetTools.ashx?toolsId=' + row.toolsId + "&action=delete",
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#tt').datagrid('reload');
                                }
                                else {
                                    $.messager.alert("提示", "删除失败，请重新操作！", "info");
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }
    </script>
    <style>       

            .fitem label {
                width:100px;
                line-height: 24px;
            }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>
                <td style="padding-left: 2px">

                    <div style="padding: 2px;">
                        <a id="btnedit" href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'" style="display:none;">修改</a>
                        <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>                                     
                        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="outword()">导出</a>

                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
            data-options="closed:true,buttons:'#dlg-buttons',shadow:false">
    <form id="fm" method="post">
         <div class="fitem">
                    <label>昆虫：</label>
                <input id="mhid"  name="mhid" style="width:200px;" />
                </div>
                <div class="fitem">
                    <label>主要树种：</label>
                     <input id="mpid"  name="mpid" style="width:200px;" />
                    <input name="Test" id="test" type="hidden" />
                    <input name="uid" id="uid" type="hidden" />                    
                    <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
                </div>
                <div class="fitem">
                    <label>诱虫数量（雌）：</label>
                    <input id="femaleCount" name="femaleCount" class="easyui-validatebox" data-options="required:true,validType:'number'" />
                </div>
                <div class="fitem">
                    <label>诱虫数量（雄）：</label>
                    <input id="maleCount" name="maleCount" class="easyui-validatebox" data-options="required:true,validType:'number'" />
                </div>

    </form>
        </div>
     <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>
</asp:Content>

